from app.db.base_class import Base, gen_uuid
from sqlalchemy import Boolean, Column, Integer, String, VARCHAR, BIGINT, SmallInteger, DateTime, ForeignKey, Text
from datetime import datetime
from sqlalchemy_serializer import SerializerMixin
from sqlalchemy.orm import relationship
from app.models.system import Users


class GenerateImageRecord(Base, SerializerMixin):
    __tablename__ = "generate_image_record"
    __table_args__ = ({'comment': '生成图片记录表'})

    user_id = Column(Integer, ForeignKey('system_users.id', ondelete='CASCADE'))
    user = relationship('Users', backref='generate_image')
    params = Column(Text, nullable=True, comment="参数")
    number = Column(Integer, default=1, comment="数量", server_default="1")
    type = Column(Integer, default=1, comment="类型", server_default="1")
    state = Column(Integer, default=1, comment="状态", server_default="1")


class GenerateImageResult(Base, SerializerMixin):
    __tablename__ = "generate_image_result"
    __table_args__ = ({'comment': '生成图片结果表'})

    record_id = Column(Integer, ForeignKey('generate_image_record.id', ondelete='CASCADE'))
    record = relationship('GenerateImageRecord', backref='generate_image_result')
    path = Column(VARCHAR(512), comment="路径")


class GenerateTextRecord(Base, SerializerMixin):
    __tablename__ = "generate_text_record"
    __table_args__ = ({'comment': '生成文本结果表'})

    user_id = Column(Integer, ForeignKey('system_users.id', ondelete='CASCADE'))
    user = relationship('Users', backref='generate_text')

    problem = Column(VARCHAR(1024), comment="问题")
    state = Column(Integer, default=1, comment="状态", server_default="1")
    answer = Column(Text, nullable=True, comment="答案")
    answer_time = Column(DateTime, nullable=True, comment="生成答案时间")
    history = Column(Text, nullable=True, comment="历史")

    draw = Column(Integer, default=0, comment="是否画图", server_default="0")
    publish = Column(Integer, default=0, comment="是否发布", server_default="0")


class GenerateBackImage(Base, SerializerMixin):
    __tablename__ = "generate_back_image"
    __table_args__ = ({'comment': '生成背景图'})
    path = Column(VARCHAR(512), comment="路径")
    name = Column(VARCHAR(256), comment="名字")


class GenerateTextImageResult(Base, SerializerMixin):
    __tablename__ = "generate_back_image_result"
    __table_args__ = ({'comment': '文本生成图片结果'})

    text_id = Column(Integer, ForeignKey('generate_text_record.id', ondelete='CASCADE'))
    text = relationship('GenerateTextRecord', backref='generate_text_image')
    path = Column(VARCHAR(512), comment="路径")


class ServerList(Base, SerializerMixin):
    __tablename__ = "server_list"
    __table_args__ = ({'comment': '服务列表'})
    name = Column(VARCHAR(256), comment="名字")
    state = Column(Integer, default=0, comment="状态", server_default="0")
    uid = Column(VARCHAR(256), comment="UID")
    detail = Column(VARCHAR(512), nullable=True, comment="详情")


class ModelList(Base, SerializerMixin):
    __tablename__ = "model_list"
    __table_args__ = ({'comment': '模型列表'})
    name = Column(VARCHAR(256), comment="名字", unique=True)
    path_name = Column(VARCHAR(512), comment="路径名字", unique=True)
    detail = Column(VARCHAR(512), nullable=True, comment="详情")
    image = Column(VARCHAR(512), comment="图片", nullable=True)
    type = Column(Integer, default=1, comment="类型", server_default="1")
